﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EasierRdp.Models;
using EasierRdp.Util;

namespace EasierRdp
{
    partial class ServerDialog : Form
    {
        public RdpServer Server { get; set; }

        public ServerDialog()
        {
            InitializeComponent();
            this.DialogResult = DialogResult.None;
        }

        private void ButtonOk_Click(object sender, EventArgs e)
        {
            if (Server == null)
            {
                Server = new RdpServer(Text_Server.Text);
            }
            else
            {
                Server.Name = Text_Server.Text;
            }
            Server.Port = TextPort.Text.ParseNullableInt();
            RdpContext.AddServer(Server);
            this.DialogResult = DialogResult.OK;
            this.Hide();
            EasierRdpEvents.RebindTreeView();
        }

        private void ServerDialog_Load(object sender, EventArgs e)
        {
            if (Server != null)
            {
                Text_Server.Text = Server.Name;
                TextPort.Text = Server.Port.ToString();
            }
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
